clc
clear all
close all

%读取数据
filename='2022-11-22 00_00_00.csv';
filename ='数据集.xlsx';
table = readtable(filename);

%时间和数据分开保存
timestamps=table(:,1);
data=table(:,2:end);
data=table2array(data);

%初始化专家系统阈值及输出调整量
CurrentShrehold = [140 180];    %电流阈值
WaterChange = zeros(length(data),1);  %初始化输出值
Status = zeros(length(data),1);
%专家系统
for i = 1:length(data)
    %第一层判断电流和成球率
    %棍子转速[15-16]
    SpeedSetA = data(i,14);
    SpeedSetB = data(i,15);
    
    CurrentShreholdA = CurrentShrehold-SpeedSetA;
    CurrentShreholdB = CurrentShrehold-SpeedSetB;

    CurrentFlag = 0;
    
    %{7,11]AB电流
    CurrentA = data(i,6);
    CurrentB = data(i,10);

    %{8,12]AB电流_1min
    CurrentA_1min = data(i,7);
    CurrentB_1min = data(i,11);

    %[27]BallRatio
    %{28]ZZ208
    BallRatio = data(i,26);
    ZZ208 = data(i,27);

    if(CurrentA>CurrentShreholdA(2) &&CurrentA_1min>0.1)
        mode = 4;
        CurrentFlag = CurrentFlag+0.7;
        if(CurrentB>CurrentShreholdB(2) &&CurrentB_1min>0.1)
            CurrentFlag = CurrentFlag+0.3;
        end
    elseif(CurrentA<CurrentShreholdA(1) &&CurrentA_1min<-0.1)
        if(BallRatio<0.50)
            mode =1;
        else
            mode =2;
        end
        CurrentFlag = CurrentFlag-0.7;
        if(CurrentB<CurrentShreholdB(1) &&CurrentB_1min<-0.1)
            CurrentFlag = CurrentFlag-0.3;
        end
    else
        mode = 3;
    end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
score = 0;
%[6]返料仓_10min
ReturnBin_10min = data(i,5);
switch mode
    case 1
        if(ZZ208<3)
            score = 0;
            Status(i) = 10*mode+2;
        else
            if(BallRatio<0.50)
                score = score+1;
            end
            if(ZZ208<5)
                score =score+1;
            end
            if(ReturnBin_10min>0.1)
                score = score+1;
            end
            Status(i) = 10*mode+1;
        end
    if(score*abs(CurrentFlag)>2)
        WaterChange(i) = 0.2;
    end
    case 2
    case 3
    case 4
end

end